<template>
	<view class="order-tep">
		<!-- <view class="bg" style="">
			<search placeText='请输入订单关键词' bg="#F4F4F4"></search>
		</view> -->
		<view class="">
			<view class="content text-center" style="min-height: 500rpx;" v-if="!orderList.length">
				<view class="" style="margin-top: 20rpx;">
					<u-empty mode="order" text-size="20px"></u-empty>
				</view>
			</view>
			<view class="content" style="min-height: 500rpx;" v-else>
				<view class="card w96">
					<scroll-view scroll-y="true" :scroll-top="0" class="scroll_views" @scrolltolower="lower"
						@scroll="scroll" refresher-enabled="true" :refresher-triggered="triggered"
						:refresher-threshold="100" refresher-background="lightgreen" @refresherpulling="onPulling"
						@refresherrefresh="onRefresh" @refresherrestore="onRestore" @refresherabort="onAbort">
						<view class="w96 radius20 bgwhite mt20" style="padding: 0 20rpx 20rpx 0rpx;"
							v-for="i in orderList" :key="i.id" @click="make(i)">
							<view v-if="i.is_refund == 2" class="w94"
								style="padding: 30rpx 0 0 30rpx; font-size: 32rpx;">
								待退款
								<view class="small-size" style="padding: 20rpx 0;margin: 0 auto;color: #ccc;">
									退款申请已交由平台处理
								</view>
							</view>
							<view v-else-if="i.is_refund == 3" class="w94"
								style="padding: 30rpx 0 0 30rpx; font-size: 32rpx;">
								退款成功
							</view>
							<block v-else>
								<view v-if="i.is_pay == 1" class="w94"
									style="padding: 30rpx 0 0 30rpx; font-size: 32rpx;">
									已结算
									<view class="small-size" style="padding: 20rpx 0;margin: 0 auto;color: #ccc;">
										订单结束
									</view>
								</view>

								<view v-else>
									<view v-if="i.order_status == 1" class="w94"
										style="padding: 30rpx 0 0 30rpx; font-size: 32rpx;">
										已报价
									</view>
									<view v-if="i.order_status == -1" class="w94"
										style="padding: 30rpx 0 0 30rpx; font-size: 32rpx;">
										已取消
									</view>
									<view v-else-if="i.order_status == 2" class="w94"
										style="padding: 30rpx 0 0 30rpx; font-size: 32rpx;">
										待服务
										<view class="small-size"
											style="padding: 20rpx 0rpx;margin: 0 auto;color: #ccc;">
											您已接单，待上门服务
										</view>
									</view>
									<view v-else-if="i.order_status == 2.1" class="w94"
										style="padding: 30rpx 0 0 30rpx; font-size: 32rpx;">
										待服务（催单）
										<view class="small-size" style="padding: 20rpx 0;margin: 0 auto;color: #ccc;">
											您已接单，待上门服务
										</view>
									</view>
									<view v-else-if="i.order_status == 2.2" class="w94"
										style="padding: 30rpx 0 0 30rpx; font-size: 32rpx;">
										施工中
										<view class="small-size" style="padding: 20rpx 0;margin: 0 auto;color: #ccc;">
											等待您施工完成
										</view>
									</view>
									<view v-if="i.order_status==3&& i.is_pay==0" class="w94"
										style="padding: 30rpx 0 0 30rpx; font-size: 32rpx;">
										待结算
										<view class="small-size" style="padding: 20rpx 0;margin: 0 auto;color: #ccc;">
											订单已完成，等待客户进行结算支付
										</view>
									</view>
								</view>
							</block>
							<view class="flex" style="padding: 0 20rpx;">
								<image :src="i.goods_photo.split(',')[0]" v-if="i.goods_photo.split(',')"
									style="width: 140rpx;height: 140rpx;margin: 20rpx; border: 1px solid;border-radius: 16rpx;"
									mode=""></image>
								<image src="@/static/lg.png" v-else
									style="width: 140rpx;height: 140rpx;margin: 20rpx; border: 1px solid;border-radius: 16rpx;"
									mode=""></image>
								<view class="flex" style="flex-direction: column;justify-content: space-evenly;">
									<view style="font-size: 28rpx;">{{i.goods_name||'橱柜'}}</view>
									<view class="small-size" style="color:#ccc">服务内容:{{i.category_name||'维修'}}</view>
									<view class="small-size" style="color:#ccc">
										下单时间:{{format(i.createtime*1000)||'2012-12-01'}}</view>
								</view>
							</view>
							<u-line></u-line>
							<view class="tag">
								<u-tag text="查看订单" color="#000" borderColor="transparent" shape="circle"
									bg-color="#CEEE5B" @click="make(i)"></u-tag>
							</view>
						</view>
					</scroll-view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		round_order,
	} from '@/common/teacherReq';
	import search from '@/components/search.vue';
	export default {
		components: {
			search
		},
		data() {
			return {
				orderList: [],
				page: 0,
				total: 0,
				triggered: false,
				isNull: false,
				type: 1,
			};
		},
		onLoad(opt) {
			uni.setNavigationBarTitle({
				title: opt.name
			})
			this.type = opt.id
			this.getList(opt.id, 0)
			this._freshing = false;
			setTimeout(() => {
				this.triggered = true;
			}, 1000)
		},
		methods: {
			make(e) {
				/**
				 * type:1, 待服务
				 * type:2, 施工中
				 * type:3, 待结算
				 * type:4, 已结束
				 * type:5, 退款中
				 * type:6, 退款成功
				 * type:7, 待中选
				 */
				uni.navigateTo({
					url: '/subpack/order/detail?id=' + e.id
				})
			},
			getList(type, page) {
				round_order({
					type,
					page
				}).then(res => {
					console.log('res: ', res);
					if (res.data.order_list.length) {
						this.orderList = this.orderList.concat(res.data.order_list)
						this.total = res.data.total
					} else {
						this.isNull = true
					}
				})
			},
			lower(e) {
				if (this.isNull) {
					uni.showToast({
						title: '没有更多了',
						icon: 'error'
					})
					return
				}
				this.page += 1
				this.getList(this.type, this.page)
			},
			scroll(e) {
				// console.log(e, 'scroll')
			},
			onPulling(e) {
				// console.log("onpulling", e);
			},
			async onRefresh() {
				if (this._freshing) return;
				this.total = 0
				this.page = 0
				this.orderList = []
				this.isNull = false
				this._freshing = true;
				await this.getList(this.type, this.page)
				this.triggered = false;
				this._freshing = false;
			},
			onRestore() {
				this.triggered = 'restore'; // 需要重置
			},
			onAbort() {
				console.log("onAbort");
			},
			format(timestamp) {
				const date = new Date(timestamp);
				const year = date.getFullYear();
				const month = date.getMonth() + 1; // 月份从0开始，所以要加1
				const day = date.getDate();
				const hours = date.getHours();
				const minutes = date.getMinutes();
				const formattedMinutes = minutes < 10 ? `0${minutes}` : minutes;
				const formattedDate = `${year}年${month}月${day}日   ${hours}:${formattedMinutes}`;
				return formattedDate

			}
		}
	}
</script>

<style lang="scss" scoped>
	.order-tep {
		.bg {
			background-color: #fff;
			padding: 15rpx;
		}

		.tag {
			display: flex;
			justify-content: flex-end;
			width: 100%;
			margin-top: 20rpx;
		}

		.scroll_views {
			// flex: 1;
			height: calc(100vh - 100px);
			margin-top: 35px;
		}
	}
</style>